function addEmployeeInfo(){
	var default_height = 405;
	
	var deletedData = [];
	var s = new deletedDataObject();
	//s.getDeletedDataLength();

	var baseInfoPanel = getBaseInfoPanel(default_height);
	var socialSecurityNumberPanel = getSocialSecurityNumberPanel(default_height);
	var bankCardNumberPanel = getBankCardNumberPanel(default_height, baseInfoPanel.findById('emp_name'), s);

    var employeeInfoPanel = new Ext.TabPanel({
        activeTab: 0,
        width:730,
        height:default_height + 50,
		id:'employeeInfoPanel',
        plain:true,
        defaults:{autoScroll: true},
        items:[baseInfoPanel,socialSecurityNumberPanel,bankCardNumberPanel]
    });

	var win = new Ext.Window({
		buttonalign : 'right',
		closable: true,
		draggable : true,
		id:'addemployeeWin',
		//height : 200,
		//layout : 'border',
		region : 'center',
		plain : true,
		items : [employeeInfoPanel],
		title: '新增雇员信息',
		width : 750,
		buttons : [{
			text:'保存并继续新增',
			id:'_btnSaveOn',
			handler:function(){
				if (!vaildateBaseInfoPanel(baseInfoPanel)) {
					employeeInfoPanel.activate(baseInfoPanel);
					return;
				}
				var baseInfoPanelParam = generateParamsFromForm(baseInfoPanel);
				
				var socialSecurityNumberPanelParam = generateParamsFromForm(socialSecurityNumberPanel);
				
				var modifiedData = [];
				if (!getModifiedDataFromGrid(bankCardNumberPanel.findById('bankCardGrid'), modifiedData, 1)){
					employeeInfoPanel.activate(bankCardNumberPanel);
					return;
				}
				var bankCardNumberPanelParam =  '"modified":' + Ext.encode(modifiedData) + ',"deleted":' + Ext.encode(s.getDeletedData()); 
				
				
				Ext.Ajax.request({
					url:'GetAllPbEmploy!saveEmployeeInfo.action',
					method:'post',
					params:{
						baseInfoPanelParam : baseInfoPanelParam,
						socialSecurityNumberPanelParam : socialSecurityNumberPanelParam,
						bankCardNumberPanelParam : bankCardNumberPanelParam
					},
					success:function(response,options){
						win.hide();
						win.show();
					},
					failure:function(response,options){
						Ext.Msg.alert('警告','由于异常原因，提交数据失败！');
					}
				});
			}
		},{
			text:'保存',
			id : '_btnSave',
			handler:function(){
				if (!vaildateBaseInfoPanel(baseInfoPanel)) {
					employeeInfoPanel.activate(baseInfoPanel);
					return;
				}
				var baseInfoPanelParam = generateParamsFromForm(baseInfoPanel);

				var socialSecurityNumberPanelParam = generateParamsFromForm(socialSecurityNumberPanel);

				var modifiedData = [];
				if (!getModifiedDataFromGrid(bankCardNumberPanel.findById('bankCardGrid'), modifiedData, 1)){
					employeeInfoPanel.activate(bankCardNumberPanel);
					return;
				}
				var bankCardNumberPanelParam =  '"modified":' + Ext.encode(modifiedData) + ',"deleted":' + Ext.encode(s.getDeletedData()); 
				
				
				Ext.Ajax.request({
					url:'GetAllPbEmploy!saveEmployeeInfo.action',
					method:'post',
					params:{
						baseInfoPanelParam : baseInfoPanelParam,
						socialSecurityNumberPanelParam : socialSecurityNumberPanelParam,
						bankCardNumberPanelParam : bankCardNumberPanelParam
					},
					success:function(response,options){
						win.hide();
					},
					failure:function(response,options){
						Ext.Msg.alert('警告','由于异常原因，提交数据失败！');
					}
				});

			}
		},{
			text:'取消',
			id:'_btnCancel',
			handler : function(){
				win.hide();
			}
		}],
		listeners : {"beforedestroy" : function(obj) {
				return false;
			},"beforeshow":function(obj) {
				return true;
			},"beforehide":function(obj) {
				baseInfoPanel.getForm().reset();
				socialSecurityNumberPanel.getForm().reset();
				bankCardNumberPanel.findById('bankCardGrid').getStore().removeAll();
				//s.getDeletedDataLength();
				s.clearDeletedData();
				//s.getDeletedDataLength();
				win.findById('employeeInfoPanel').setActiveTab(0);
				return true;
			}
		}
	});
	return win
}

Ext.form.SystemParametersDetailStore = Ext.extend(Ext.data.Store,{
	reader: new Ext.data.JsonReader({
			root: 'results',
			id: 'parmitem_id'
		}, [
            {name:'text',mapping:'parmitem_name'},
			{name:'value',mapping:'parmitem_id'}
        ])	
});

//户口类型
function getResidentTypeCombo(){
	var resident_type_store = new Ext.form.SystemParametersDetailStore({
		 url: 'SystemParametersDetail!getSystemParametersDetail.action?id=109'
	});
				
	var resident_type_combo = new Ext.form.ComboBox({
		emptyText:'请选择户口类型',
		fieldLabel:'户口类型',
		anchor:'95%',
		name:'resident_type',
		id:'resident_type',
		store:resident_type_store,
		mode:'local',
		triggerAction:'all',
		valueField:'value',
		displayField:'text'
	});
	
	resident_type_store.load();
	return resident_type_combo;
}

//婚姻状况
function getMarriageStatusCombo(){
	var marriageStatusStore = new Ext.form.SystemParametersDetailStore({
		 url: 'SystemParametersDetail!getSystemParametersDetail.action?id=110'
	});
				
	var marriageStatusCombo = new Ext.form.ComboBox({
		emptyText:'请选择婚姻状况',
		fieldLabel:'婚姻状况',
		anchor:'95%',
		name:'marriage_status',
		id:'marriage_status',
		store:marriageStatusStore,
		mode:'local',
		triggerAction:'all',
		valueField:'value',
		displayField:'text'
	});
	
	marriageStatusStore.load();
	return marriageStatusCombo;	
}

//证件类型
function getIdCardTypeCombo(){
	var idCardType_store = new Ext.form.SystemParametersDetailStore({
		 url: 'SystemParametersDetail!getSystemParametersDetail.action?id=108'
	});
				
	var idCardTypeComboBox = new Ext.form.ComboBox({
		emptyText:'请选择证件类型',
		fieldLabel:'证件类型',
		anchor:'95%',
		name:'id_card_type',
		id:'id_card_type',
		store:idCardType_store,
		mode:'local',
		triggerAction:'all',
		valueField:'value',
		displayField:'text'
	});
	
	idCardType_store.load();
	return idCardTypeComboBox;
}

//政治面貌
function getPolity(){
	var polityStore = new Ext.form.SystemParametersDetailStore({
		 url: 'SystemParametersDetail!getSystemParametersDetail.action?id=106'
	});
				
	var polityComboBox = new Ext.form.ComboBox({
		emptyText:'请选择政治面貌',
		fieldLabel:'政治面貌',
		anchor:'95%',
		name:'polity',
		id:'polity',
		store:polityStore,
		mode:'local',
		triggerAction:'all',
		valueField:'value',
		displayField:'text'
	});
	
	polityStore.load();
	return polityComboBox;
}

//民族
function getNationality(){
	var nationality_store = new Ext.form.SystemParametersDetailStore({
		 url: 'SystemParametersDetail!getSystemParametersDetail.action?id=116'
	});
				
	var nationalityComboBox = new Ext.form.ComboBox({
		emptyText:'请选择民族',
		fieldLabel:'民族',
		anchor:'95%',
		name:'nationality',
		id:'nationality',
		store:nationality_store,
		mode:'local',
		triggerAction:'all',
		valueField:'value',
		displayField:'text'
	});
	
	nationality_store.load();
	return nationalityComboBox;
}

function getHealthStatus(){
	 return new Ext.form.ComboBox({
		fieldLabel : '健康状态',
		store : new Ext.data.SimpleStore({
			fields : ['value', 'text'],
			data : [['0','健康'],['1','一般'],['2','差']]
		}),
		displayField : 'text',
		valueField : 'value',
		mode : 'local',
		triggerAction : 'all',
		selectOnFocus : true,
		anchor : '95%',
		id:'health_status',
		name:'health_status'
	});	
}

//学历
function getEducationLevelCombo(){
	var EducationLevelStore = new Ext.form.SystemParametersDetailStore({
		 url: 'SystemParametersDetail!getSystemParametersDetail.action?id=107'
	});
				
	var EducationLevelComboBox = new Ext.form.ComboBox({
		emptyText:'请选择学历',
		fieldLabel:'学历',
		anchor:'95%',
		name:'education_level',
		id:'education_level',
		store:EducationLevelStore,
		mode:'local',
		triggerAction:'all',
		valueField:'value',
		displayField:'text'
	});
	EducationLevelStore.load();
	return EducationLevelComboBox;
}

function getBaseInfoPanel(default_height) {

	var tree = getOrgTree();

	var baseInfoPanel = new Ext.form.FormPanel({
		title:'基本信息',
		id:'baseInfoPanelForm',
		frame:true,
		height:default_height,
		bodyStyle:'padding:5px 5px 0',
		items:[{
			layout:'column',
			items:[{
				columnWidth:1,
				layout:'form',
				items:[{
					xtype:'hidden',
					name:'employee_id',
					id:'employee_id'
				},{
					xtype:'textfield',
					fieldLabel: '<font color=red>*</font>雇员编号',
					name:'emp_code',
					id:'emp_code',
					anchor:'80%',
					allowBlank:false,
					blankText:'雇员编号不能为空',
					emptyText:'请输入雇员编号'
				}]
			},{
				columnWidth:.5,
				layout:'form',
				items:[{
					xtype:'textfield',
					fieldLabel: '<font color=red>*</font>雇员姓名',
					name: 'emp_name',
					id:'emp_name',
					anchor:'95%',
					allowBlank:false,
					blankText:'雇员姓名不能为空',
					emptyText:'请输入雇员姓名'
				},new Ext.form.DateField({
					format:'Y-m-d',
					fieldLabel:'出生日期',
					anchor:'95%',
					id:'birthday',
					name:'birthday',
					emptyText:'请输入出生日期'
				}),
					getHealthStatus(),
					getIdCardTypeCombo(),
					getEducationLevelCombo(),
					getResidentTypeCombo()
				]
			},{
				columnWidth:.5,
				layout:'form',
				items:[getGenderCombo()
				 ,	getNationality()
				 ,  getPolity()
				 ,{
					xtype:'textfield',
					fieldLabel:'证件号码',
					anchor:'95%',
					id:'id_card_num',
					name:'id_card_num',
					emptyText:'请输入证件号码'
				},getMarriageStatusCombo(),
				  {
					xtype:'textfield',
					fieldLabel:'邮箱',
					anchor:'95%',
					id:'email',
					name:'email',
					emptyText:'请输入电子邮箱地址'
				}]				
			},{
				columnWidth:1,
				layout:'form',
				items:[{
					xtype:'textfield',
					fieldLabel:'户口地址',
					anchor:'98%',
					id:'resident_address',
					name:'resident_address',
					emptyText:'请输入户口地址'
				},{
					xtype:'textfield',
					fieldLabel:'联系地址',
					anchor:'98%',
					id:'address',
					name:'address',
					emptyText:'请输入联系地址'
				}]
			},{
				columnWidth:.5,
				layout:'form',
				items:[{
					xtype:'textfield',
					fieldLabel:'邮编',
					anchor:'95%',
					id:'postcode',
					name:'postcode',
					emptyText:'请输入邮编'
				},{
					xtype:'textfield',
					fieldLabel:'手机',
					anchor:'95%',
					id:'contact_tel3',
					name:'contact_tel3',
					emptyText:'请输入手机号码'
				}]
			},{
				columnWidth:.5,
				layout:'form',
				items:[{
					xtype:'textfield',
					fieldLabel:'联系电话1',
					anchor:'95%',
					id:'contact_tel1',
					name:'contact_tel1',
					emptyText:'请输入联系电话'
				},{
					xtype:'textfield',
					fieldLabel:'联系电话2',
					anchor:'95%',
					id:'contact_tel2',
					name:'contact_tel2',
					emptyText:'请输入联系电话'
				}]
			},{
				columnWidth:.5,
				layout:'form',
				items:[{
					xtype:'combotree',
					fieldLabel:'部门',
					anchor:'95%',
					id:'department',
					name:'department',
					emptyText:'请选择雇员所在部门',
					tree:tree
				},{
					xtype:'numberfield',
					anchor:'95%',
					fieldLabel:'<font color=red>*</font>转正前工资',
					id:'base_pay_pro',
					name:'base_pay_pro',
					emptyText:'请输入转正前工资',
					blankText:'转正前工资不能为空',
					allowBlank:false
				}, new Ext.form.DateField({
					fieldLabel:'<font color=red>*</font>入职日期',
					emptyText:'请输入入职日期',
					format:'Y-m-d',
					anchor:'95%',
					id:'join_date',
					name:'join_date',
					allowBlank:false,
					blankText:'入职日期不能为空'
				}),new Ext.form.DateField({
					fieldLabel:'转正日期',
					emptyText:'请输入转正日期',
					anchor:'95%',
					format:'Y-m-d',
					id:'in_jobdate',
					name:'in_jobdate'
				})]
			},{
				columnWidth:.5,
				layout:'form',
				items:[new Ext.form.ComboBox({
					fieldLabel : '<font color=red>*</font>合同类型',
					store : new Ext.data.SimpleStore({
						fields : ['value', 'text'],
						data : [['0','劳动合同'],['1','劳务合同']]
					}),
					displayField : 'text',
					valueField : 'value',
					mode : 'local',
					triggerAction : 'all',
					selectOnFocus : true,
					anchor : '95%',
					id:'contract_type',
					name:'contract_type',
					allowBlank:false
				}),{
					xtype:'numberfield',
					anchor:'95%',
					fieldLabel:'<font color=red>*</font>合同工资',
					id:'base_pay',
					name:'base_pay',
					emptyText:'请输入合同工资',
					allowBlank:false,
					blankText:'合同工资不能为空'
				},new Ext.form.DateField({
					fieldLabel:'工龄起算年份',
					anchor:'95%',
					format:'Y',
					emptyText:'请输入工龄起算年份',
					id:'service_start',
					name:'service_start'
				}),new Ext.form.DateField({
					fieldLabel:'离职日期',
					emptyText:'请输入离职日期',
					anchor:'95%',
					format:'Y-m-d',
					name:'out_jobdate',
					id:'out_jobdate'
				})]
			}]
		}]		
	});	
	
	return baseInfoPanel;
}

function getSocialSecurityNumberPanel(default_height){
	var socialSecurityNumberPanel = new Ext.form.FormPanel({
		frame:true,
		height:default_height,
		title:'账号信息',
		id:'socialSecurityNumberPanel',
		bodyStyle:'padding:5px 5px 0',
		items:[{
			xtype:'textfield',
			fieldLabel:'社保账号',
			name:'socialSecurityNumber',
			id:'socialSecurityNumber',
			anchor:'95%'
		},{
			xtype:'textfield',
			fieldLabel:'公积金账号',
			name:'surplusAccount',
			id:'surplusAccount',
			anchor:'95%'
		}]
	}); 
	
	return socialSecurityNumberPanel;
}

function getBankCardNumberPanel(default_height,default_account_name,deletedObject){
	var deletedJson = [];

	var sm = new Ext.grid.CheckboxSelectionModel();
	var store = new Ext.data.Store({
		//url:'CusAdmin!queryAdminSystem.action',
		proxy:new Ext.data.MemoryProxy(Ext.util.JSON.decode("[]")),
		pruneModifiedRecords:true,
		reader: new Ext.data.JsonReader({
			root:'cards',
			id: 'bankcard_id'
			//totalProperty: 'result.totalCount'
		},[
			{name:'bankcard_id',mapping:'bankcard_id'},
			//{name:'bank_type',mapping:'bank_type'},
			{name:'bank_id',mapping:'bank_id'},
			//{name:'bank_chinese_name',mapping:'bank_chinese_name'},
			{name:'bank_code',mapping:'bank_code'},
			{name:'bank_name',mapping:'bank_name'}
			//{name:'is_valid',mapping:'is_valid'}
		])
	});

	var cm = new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),
		sm,
		{header: '开户行', dataIndex: 'bank_id',width:200,editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlank:false}))},
		{header: '卡号', dataIndex: 'bank_code',width:300,editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlank:false}))},
		{header: '开户名', dataIndex: 'bank_name',width:150,editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlank:false}))}
	]);
	
	var account = Ext.data.Record.create([
		{name:'bankcard_id',type:''},
		{name:'bank_id',type:'text'},
		{name:'bank_code',type:'text'},
		{name:'bank_name',type:'text'}
	]);

	var addAction = new Ext.Action({
		text:'新增',
		handler:function(){
			var initValue;
			if (default_account_name != null && typeof(default_account_name) == 'object') {
				initValue = {bankcard_id:'',bank_id:'',bank_code:'',bank_name:default_account_name.getValue()};
			} else {
				initValue = {bankcard_id:'',bank_id:'',bank_code:'',bank_name:''};
			}
			var p = new account(initValue);
			bankCardGrid.stopEditing();
			store.insert(0,p);
			bankCardGrid.startEditing(0,2);
			bankCardGrid.view.refresh();
			p.dirty=true;
			p.modified = initValue;
			if (store.modified.indexOf(p) == -1) {
				store.modified.push(p);
			}
		}
	});

	var delAction = new Ext.Action({
		text:'删除',
		handler:function(){
			var length = bankCardGrid.getSelectionModel().getSelections().length;
			if (length > 0){
				Ext.MessageBox.show({
					title:'提示',
					msg:'您选中了' + length + '条记录进行删除,请问您确认吗?',
					buttons:Ext.MessageBox.OKCANCEL,
					fn:function(btn) {
						if (btn == "ok"){
							var rs = bankCardGrid.getSelectionModel().getSelections();
							for (var i = 0;i < length ; i++){
								if (rs[i].data.bankcard_id != "") {
									deletedJson.push(rs[i].data);
									if (deletedObject != null) {
										deletedObject.putDeletedData(rs[i].data);
									}
								}
								
								store.remove(store.getById(rs[i].id));
								//deletedObject.getDeletedDataLength();
							};
						}
						if (btn == "cancel"){
							return;
						}
					}
				});
			} else {
				Ext.Msg.alert('警告','请选择需要删除的记录.');
			}		
		}
	});

	var bankCardGrid = new Ext.grid.EditorGridPanel({
		height:default_height,
		id:'bankCardGrid',
		tbar:[addAction,delAction],
		sm:sm,
		cm:cm,
		store:store,
		loadMask: true,
		loadMask:{msg:'正在加载数据...'}
		//autoExpandColumn:2
	});
	
	var bankCardNumberPanel = new Ext.form.FormPanel({
		frame:true,
		height:default_height,
		title:'银行卡信息',
		id:'bankCardNumberPanel',
		bodyStyle:'padding:5px 5px 0',
		items:[bankCardGrid]
	});

	return bankCardNumberPanel;
}

function generateParamsFromForm(v){
	var _rtn = '';
	if ('form' == v.getXType()) {
		//alert('field:' + v.findByType('field',false).length);
		//alert('textfield:' + v.findByType('textfield',false).length);
		var fields = v.findByType('field',false);
		for (var length = 0; length < fields.length; length++) {
			if (_rtn != '') {
				_rtn = _rtn + ","	
			} 
			//处理未初始化的控件
			if (typeof(fields[length].getValue()) == "undefined"){
				_rtn = _rtn + '"' + fields[length].getId() + '":""'
				continue
			}
			//处理日期类型的控件
			if (fields[length].getXType() == 'datefield') {
				//控件未被赋值
				if (typeof(fields[length].getValue()) == 'string'){
					_rtn = _rtn + '"' + fields[length].getId() + '":"' + fields[length].getValue() + '"'
				} else {
					_rtn = _rtn + '"' + fields[length].getId() + '":"' + fields[length].getValue().format(fields[length].format) + '"'	
				}
			} else {		
				_rtn = _rtn + '"' + fields[length].getId() + '":"' + fields[length].getValue() + '"'
			}
		}
		_rtn = '"' + v.getId() + '":{' + _rtn + "}";
	}
	return _rtn;
}


function getModifiedDataFromGrid(grid, modifiedArray, startCell){
	//开始校验列数
	var sc = 0;

	if (grid.getXType() != 'editorgrid' || modifiedArray == null){
		//alert('不合法数据')
		return;
	}
	if (startCell != null){
		sc = startCell;
	}

	var modified = [];
	if (grid.getXType() == 'editorgrid'){
		modified = grid.getStore().modified.slice(0);
		//alert(modified.length + "条数据处理");
		//校验EditorGrid数据的合法性
		for (var i = 0; i < modified.length; i++) {
			var record = modified[i];
			var fields=record.fields.keys;
			
			for (var j = sc; j<fields.length; j++) {
				var name = fields[j];
				var value = record.data[name];

				var colIndex = grid.getColumnModel().findColumnIndex(name);
				var rowIndex = grid.getStore().indexOfId(record.id);
				var editor = grid.getColumnModel().getCellEditor(colIndex).field;

				if (!editor.validateValue(value)){
					Ext.Msg.alert('提示','输入的数据不正确',function(){
						grid.startEditing(rowIndex,colIndex);
					});
					return false;
				}
			}
		}

		//将EditorGird数据转换成JSON
		Ext.each(modified,function(item){
			//alert(item.data);
			modifiedArray.push(item.data);
		});
		//alert(modifiedArray.length);
		return true;
	}
}


function vaildateBaseInfoPanel(baseInfoPanel) {
	if (!baseInfoPanel.findById('emp_code').validate()){
		baseInfoPanel.findById('emp_code').focus();
		return false;
	}
	if (!baseInfoPanel.findById('emp_name').validate()){
		baseInfoPanel.findById('emp_name').focus();
		return false;
	}
	if (!baseInfoPanel.findById('contract_type').validate()){
		baseInfoPanel.findById('contract_type').focus();
		return false;
	}
	if (!baseInfoPanel.findById('base_pay_pro').validate()){
		baseInfoPanel.findById('base_pay_pro').focus();
		return false;
	}
	if (!baseInfoPanel.findById('base_pay').validate()){
		baseInfoPanel.findById('base_pay').focus();
		return false;
	}
	if (!baseInfoPanel.findById('join_date').validate()){
		baseInfoPanel.findById('join_date').focus();
		return false;
	}
	return true;
}



function deletedDataObject(){
	this.deletedData = [];

	this.getDeletedDataLength = function(){alert(this.deletedData.length);}
	this.clearDeletedData = function(){this.deletedData = [];}
	this.putDeletedData = function(data){this.deletedData.push(data);}
	this.getDeletedData = function(){return this.deletedData;}
}
